Skip to content

Refactor septidon for the generic on field#19

Merged
noel2004 merged 6 commits intomainfrom
septidon-refactor
Apr 8, 2023
Merged

Refactor septidon for the generic on field#19
noel2004 merged 6 commits intomainfrom
septidon-refactor

Conversation

@noel2004
Copy link
Member

@noel2004 noel2004 commented Apr 3, 2023

Current the code (SpongeChip) under "short" feature (i.e. septidon is applied) can not be wrapped into mpt and zkevm circuits for lacking of the generic on field. Notice the external caller consider poseidon circuit is generic by field with Hashable trait as constraints, we can not specializate it to bn254's field type too early.

Here we have launched a wide range refactoring with noticing the original Hashable trait is not enough for sepctidon, since it require a 'cached' permutation constants being provided. We have to switch the Hashable trait by different feature (from the original P128pow5t3 to extended CachedConstant), and update most of the septidon code with a field generic.

@noel2004 noel2004 added the enhancement New feature or request label Apr 3, 2023
Copy link

@ControlCplusControlV ControlCplusControlV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I just had a couple of questions as someone reading through scroll repos :), if you don't mind answering it would be appreciated but also understand if you'd rather not have the PR clutter and can stop

@noel2004 noel2004 requested a review from naure April 6, 2023 12:57
Copy link
Contributor

@naure naure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement! See comments.

/// This implementation supports only the scalar field of BN254 at the moment.
///
/// To implement for the Pasta curves, adjust the parameters below, and replace the transition round
/// by a copy, to get 56 rounds instead of 57.
Copy link
Contributor

@naure naure Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This circuit does implement exactly 57 partial rounds, which is why it is not generic over any field. There should be at least an assert somewhere to check this. Maybe repeat this comment too in case someone wants to implement 56 rounds.

pub mod sbox {
use super::super::util::pow_5;
use super::F;
use halo2_proofs::arithmetic::FieldExt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not compile at the moment.

We changed some things in halo2 recently to use the trait PrimeField instead of FieldExt, that might be the problem. See #13

compile error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is cause by the halo2 lib depency: the scroll-dev-1220 use another poseidon lib without a tag so it points to some unstable code and issue raised after several updating in the codebase.

I had update halo2 to scroll-dev-0220 (which is consistent with current zkevm-circuit) and the issue has been resolved.

@naure
Copy link
Contributor

naure commented Apr 6, 2023

it require a 'cached' permutation constants being provided

This is no different than the existing traits (P128Pow5T3Constants, etc), and the constants here could be wrapped in the implementation of it.

It’s just that these traits are very complicated, which is why I chose initially the simpler way with lazy_static functions. Ideally, it is this entire system of types that could be simplified. See "the map of types".

@noel2004
Copy link
Member Author

noel2004 commented Apr 8, 2023

it require a 'cached' permutation constants being provided

This is no different than the existing traits (P128Pow5T3Constants, etc), and the constants here could be wrapped in the implementation of it.

It’s just that these traits are very complicated, which is why I chose initially the simpler way with lazy_static functions. Ideally, it is this entire system of types that could be simplified. See "the map of types".

Great, we could purpose another refactor / simplification later

@noel2004 noel2004 merged commit 85b0f06 into main Apr 8, 2023
@noel2004 noel2004 deleted the septidon-refactor branch December 1, 2023 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants